package tony.com.test;

import android.util.Log;
import android.widget.Button;
import android.widget.EditText;

import com.android.volley.VolleyError;

import java.util.HashMap;
import java.util.Map;


import tony.com.xframe.acitivity.BaseActivity;
import tony.com.xframe.network.VolleyListener;
import tony.com.xframe.network.VolleyUtil;

/**
 * Created by Tony on 2015-12-31.
 */
public class NetWorkTestActivity extends BaseActivity {
    private EditText editText;
    private Button btnPost;

    @Override
    public int getLayoutId() {
        return R.layout.test;
    }


    @Override
    public void initWidge() {
        editText = (EditText) findViewById(R.id.editText);
        btnPost = (Button) findViewById(R.id.button);
        btnPost.setOnClickListener(this);
    }

    @Override
    public void widgeClick(int viewId) {
        switch (viewId) {
            case R.id.button:
                getData();
                break;
            case R.id.editText:
                break;
        }

    }

    private void getData() {
        String url = "http://apis.juhe.cn/mobile/get";
        Map<String, String> params = new HashMap<>();
        params.put("phone",editText.getText().toString().trim());
        params.put("key", "8076f270c923baec784966295058d802");
        VolleyUtil.getIntance().getNetResult(this, url, "post", new VolleyListener() {
            @Override
            public void onSuccess(String result) {
                Log.i("info",result);
            }

            @Override
            public void onFailure(VolleyError volleyError) {
                Log.e("info",volleyError.toString());
            }
        }, params);
    }
}
